package com.intermancer.predictor.lifecycle;

import java.util.ArrayList;
import java.util.List;

import com.intermancer.predictor.feeder.Feeder;
import com.intermancer.predictor.organism.Organism;
import com.intermancer.predictor.store.StoreEntry;
import com.intermancer.predictor.store.StoreEntryDAO;

public class FeedCommand extends LifecycleCommandBase {
	
	private Feeder feeder;
	private StoreEntryDAO storeEntryDAO;
	
	public FeedCommand() {
		// Nothing.
	}
	
	public FeedCommand(Feeder feeder, StoreEntryDAO storeEntryDAO) {
		this.feeder = feeder;
		this.storeEntryDAO = storeEntryDAO;
	}

	@Override
	boolean innerExecute(LifecycleContext context) {
		List<StoreEntry> storeEntries = new ArrayList<StoreEntry>();
		for(Organism organism : context.getChildren()) {
			StoreEntry storeEntry = new StoreEntry();
			storeEntry.setOrganism(organism);
			feeder.setOrganism(organism);
			feeder.init();
			feeder.feedOrganism();
			storeEntry.setScore(feeder.getEvaluator().getScore());
			storeEntries.add(storeEntry);
		}
		context.setStoreEntries(storeEntries);
		return false;
	}

	public Feeder getFeeder() {
		return feeder;
	}

	public void setFeeder(Feeder feeder) {
		this.feeder = feeder;
	}

	public StoreEntryDAO getStoreEntryDAO() {
		return storeEntryDAO;
	}

	public void setStoreEntryDAO(StoreEntryDAO storeEntryDAO) {
		this.storeEntryDAO = storeEntryDAO;
	}

}
